#ifndef LOADERS_H
#define LOADERS_H

typedef enum
{
    LOAD_OK,
    LOAD_FAIL
} LoadResult;

typedef enum
{
    FILETYPE_ERROR,
    FILETYPE_UNKNOWN,
    FILETYPE_PBP,
    FILETYPE_ELF,
    FILETYPE_ISO
} EmuFileType;

typedef struct
{
    char magic[4]; /* '\0PSF' */
    u32 ver; /* 0x00000101 */
    u32 keyoff; /* offset to the key table */
    u32 valueoff; /* offset to the value table */
    u32 num; /* number of key/value pairs */
} PsfHeader;

typedef struct
{
    u16 keyoff; /* offset of the key name in the key table */
    u8 four; /* always 4 */
    u8 type; /* data type of the value */
    u32 size; /* real size of the value */
    u32 sizewithpad; /* size with padding (free space at the end of the value to make it longer in the future) */
    u32 valueoff; /* offset of the value in the value table */
} PsfEntry;

typedef enum
{
    PSF_BIN,
    PSF_TXT,
    PSF_INT,
    PSF_END
} PsfEntryType;

typedef struct
{
    PsfEntryType type;
    char *entry;
    void *value;
} PsfPair;

typedef struct
{
    char *title;
} IsoInfo;

typedef struct IsoFileNode {
    char *filename;
    IsoInfo info;
    PsfPair *pair;
    struct IsoFileNode *prev;
    struct IsoFileNode *next;
} IsoFileNode;

LoadResult load_raw(const char *filename, u32 addr);
LoadResult load_rom(const char *filename);
LoadResult load_iso(const char *filename);
LoadResult load_elf(const char *filename);
LoadResult load_pbp(const char *filename);

IsoFileNode load_findFiles(const char *path);
void load_freeFiles(IsoFileNode *root);

#endif

